//
//  ZTTwoControlDevice.m
//  YSSmartHome
//
//  Created by yanghao on 2016/11/24.
//  Copyright © 2016年 yahaong. All rights reserved.
//

#import "ZTTwoControlDevice.h"
#import "DataManager.h"
#import "MQTTSessionManager.h"
#import <XAISDK/XAIFormatDataCount.h>
@implementation ZTTwoControlDevice
- (void)setCircuitOneStatus:(NSUInteger)statu
{
    [self setCircuitStatus:statu which:1];
}
- (void)setCircuitTwoStatus:(NSUInteger)statu
{
    [self setCircuitStatus:statu which:2];
}

- (void)reciveStatus:(uint32_t)gatewayApsn
          deviceLuid:(uint64_t)deviceLuid
         triggerApsn:(uint32_t)triggerApsn
         triggerLuid:(uint64_t)triggerLuid
           timestamp:(uint32_t)timestamp
            statusID:(uint8_t)statusID
                data:(XAITLV *)data
           isHistory:(BOOL)isHistory
{
    if (!data) {
        NSLog(@"reciveStatus 收到的数据为空");
        return;
    }
    [super reciveStatus:gatewayApsn deviceLuid:deviceLuid triggerApsn:triggerApsn triggerLuid:triggerLuid timestamp:timestamp statusID:statusID data:data isHistory:isHistory];
    switch (statusID)
    {
        case 0x01:
        {
            uint8_t status = 0;
            memcpy(&status, [data getPayloadbyte], sizeof(uint8_t));
            if (isHistory)
            {
                NSString *str = nil;
                switch (self.devType)
                {
                    case ZTDeviceTypeCurtainDoubleTrack:
                    case ZTDeviceTypeTwoWaySocket:
                    case ZTDeviceTypeTwoWay0Switch:
                    case ZTDeviceTypeTwoWaySwitch:
                    {
                        if (status == ZTDeviceChannelStatusOn)
                        {
                            str = [NSString stringWithFormat:@"%@一路打开",[self getDeviceName]];
                        }
                        else
                        {
                            str = [NSString stringWithFormat:@"%@一路关闭",[self getDeviceName]];
                        }
                    }
                        break;
                    default:
                        break;
                }
                [super updateOperationWithGatewayApsn:gatewayApsn deviceLuid:deviceLuid triggerApsn:triggerApsn triggerLuid:triggerLuid timestamp:timestamp operation:str];

            }
            else
            {
                self.oneStatus = status;
                [kDataManager deviceRefreshCallBackWithType:DeviceCallbackTypeStatus];
            }
        }
            break;
        case 0x02:
        {
            uint8_t status = 0;
            memcpy(&status, [data getPayloadbyte], sizeof(uint8_t));
            if (isHistory) {
                NSString *str = nil;
                switch (self.devType)
                {
                    case ZTDeviceTypeCurtainDoubleTrack:
                    case ZTDeviceTypeTwoWaySocket:
                    case ZTDeviceTypeTwoWay0Switch:
                    case ZTDeviceTypeTwoWaySwitch:
                    {
                        if (status == ZTDeviceChannelStatusOn)
                        {
                            str = [NSString stringWithFormat:@"%@二路打开",[self getDeviceName]];
                        }
                        else
                        {
                            str = [NSString stringWithFormat:@"%@二路关闭",[self getDeviceName]];
                        }
                    }
                        break;
                    default:
                        break;
                }
                [super updateOperationWithGatewayApsn:gatewayApsn deviceLuid:deviceLuid triggerApsn:triggerApsn triggerLuid:triggerLuid timestamp:timestamp operation:str];
            }
            else
            {
                self.twoStatus = status;
                [kDataManager deviceRefreshCallBackWithType:DeviceCallbackTypeStatus];
            }
        }
            break;
        default:
            break;
    }
}
@end
